﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using MySql.Data.MySqlClient;
using System.ServiceModel;
using Server;
using Server.Processes;
using System.Net;


namespace Client
{
    public partial class Form1 : Form
    {
        public static int PORT = 8000;
        Icommunicator communicator;
        //MySqlConnection sc = new MySqlConnection(" server=localhost;user id=root;password=nir7424394;database=katom;persistsecurityinfo=True ");
       // MySqlCommand cmd;
        public Form1()
        {
            InitializeComponent();

        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void btnSave_Click(object sender, EventArgs e)
        {

            string serverAddress = "net.tcp://" + Dns.GetHostName() + ":" + PORT + "/katom";
            NetTcpBinding tcpbinding = new NetTcpBinding();
            tcpbinding.TransactionFlow = false;
            tcpbinding.Security.Transport.ProtectionLevel = System.Net.Security.ProtectionLevel.EncryptAndSign;
            tcpbinding.Security.Transport.ClientCredentialType = TcpClientCredentialType.Windows;
            tcpbinding.Security.Mode = SecurityMode.None;

            EndpointAddress server = new EndpointAddress(serverAddress);
            communicator = ChannelFactory<Icommunicator>.CreateChannel(tcpbinding, server);
            
            if (communicator.isConnected())
            {
                textPrivilage.Text = "connected";
            }
           /* try
            {
                 MySqlCommandBuilder commandBuilder = new MySqlCommandBuilder();

                sc.Open();
                cmd = new MySqlCommand("Insert into user (userID,Password,Privilage) values('" + textUserID.Text + "','" + textPassword.Text + "','" + textPrivilage.Text + "')", sc);
                cmd.ExecuteNonQuery();
                MessageBox.Show("Update Successfull to the Database");
                sc.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }*/
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            AddUserRequest request = new AddUserRequest(textUserID.Text, textPassword.Text);
             AddUserResponse respone = (AddUserResponse)communicator.sendRequest(request);

            textPassword.Text = respone.getResult();
        }

        private void pictureBox1_Click(object sender, EventArgs e)
        {

        }
    }
}
